package jstl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/test")
public class Test1Servlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	
		// 向req中放入一些数据
		req.setAttribute("username", "admin");
		req.setAttribute("password", "123456");
		req.setAttribute("login", false);
		
		req.setAttribute("city", "shanghai");
		
		
		
		int[] maths = {95,86,77,95,100};
		req.setAttribute("maths", maths);
		
		Student stu = new Student(1001,"张三",18);
		req.setAttribute("stu", stu);
		
		List<Student> stus = new ArrayList<>();
		stus.add(new Student(1002,"李四",20));
		stus.add(new Student(1003,"王五",20));
		stus.add(new Student(1004,"赵六",20));
		stus.add(new Student(1005,"田七",20));
		stus.add(new Student(1006,"八八",21));
		req.setAttribute("stus", stus);
		
		Map<Integer,Student> stusMap = new HashMap<>();
		stusMap.put(1005, new Student(1005,"刘备",40));
		stusMap.put(1006, new Student(1006,"曹操",45));
		stusMap.put(1007, new Student(1007,"孙权",42));
		req.setAttribute("stusMap", stusMap);
		
		
		// 请求转发test1.jsp
		req.getRequestDispatcher("test1.jsp").forward(req, resp);
		
		
		
		
	
	}
	
}
